import { defineStore } from 'pinia'
import { ref } from 'vue'

export interface AppSettings {
  theme: 'light' | 'dark' | 'auto'
  language: 'zh-CN' | 'en-US'
  notifications: boolean
  autoRefresh: boolean
  refreshInterval: number
}

export const useAppStore = defineStore('app', () => {
  // 应用设置
  const settings = ref<AppSettings>({
    theme: 'light',
    language: 'zh-CN',
    notifications: true,
    autoRefresh: true,
    refreshInterval: 30000
  })

  // 加载状态
  const loading = ref(false)
  const error = ref<string>('')

  // 初始化应用
  const initApp = () => {
    console.log('应用初始化完成')
  }

  // 显示成功消息
  const showSuccess = (message: string) => {
    uni.showToast({
      title: message,
      icon: 'success'
    })
  }

  // 显示错误消息
  const showError = (message: string) => {
    uni.showToast({
      title: message,
      icon: 'none'
    })
  }

  // 显示普通消息
  const showToast = (message: string) => {
    uni.showToast({
      title: message,
      icon: 'none'
    })
  }

  // 显示加载中
  const showLoading = (title: string = '加载中...') => {
    loading.value = true
    uni.showLoading({
      title,
      mask: true
    })
  }

  // 隐藏加载
  const hideLoading = () => {
    loading.value = false
    uni.hideLoading()
  }

  return {
    settings,
    loading,
    error,
    initApp,
    showSuccess,
    showError,
    showToast,
    showLoading,
    hideLoading
  }
})